package com.cuikaipeng.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cuikaipeng.entity.Company;
import com.cuikaipeng.entity.Tctype;
import com.cuikaipeng.service.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Controller
public class CompanyController {
	@Autowired
	private CompanyService ser;
	
	
	@RequestMapping("list")
	public String list(@RequestParam(defaultValue="1")Integer pageNum,Model m,Company company){
		PageHelper.startPage(pageNum, 3);
		List<Company> list = ser.list(company);
		PageInfo<Company> info = new PageInfo<Company>(list);
		m.addAttribute("list", list);
		m.addAttribute("c", company);
		m.addAttribute("pg", info);
		return "list";
	}
	
	@RequestMapping("tolist")
	public String tolist(String id,Model m){
		List<Company> company = ser.getc(id);
		List<Tctype> tctypes = ser.gett(id);
		m.addAttribute("clist", company);
		m.addAttribute("tlist", tctypes);
		return "list2";
	}
	
	@RequestMapping("toadd")
	public String toadd(String id,Model m){
		System.out.println(id+"122248484848");
		Company company = ser.getcc(id);
		m.addAttribute("t", new Tctype());
		m.addAttribute("c", company);
		return "add";
	}
	
	@RequestMapping("add")
	public String add(@ModelAttribute("t")Tctype t){
		ser.add(t);
		
		return "readable:list2";
		
	}
	@RequestMapping("del")
	public Object del(Integer id){
		return ser.del(id);
		
	}
}
